package LeetCode.month01.day23;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class No2438 {
    public static void main(String[] args) {
        System.out.println(Arrays.toString(productQueries(15, new int[][]{{0, 0}})));
    }
    public static int[] productQueries(int n, int[][] queries) {
        int len = queries.length;
        int[] res = new int[len];
        List<Integer> list = new ArrayList<>();
        int num = n;
        while(num>0){
            list.add(num%2);
            num>>=1;
        }
        for (int i = list.size() - 1; i >= 0; i--) {
            list.set(i, (int) (list.get(i)*Math.pow(2,i)));
            if(list.get(i)==0) list.remove(i);
        }
        for (int i = 0; i < len; i++) {
            long sum = 1;
            for (int j = queries[i][0]; j <= queries[i][1]; j++) {
                sum*=list.get(j);
                sum%= (long) (1e9+7);
            }
            res[i] = (int) sum;
        }
        return res;
    }
}
